package hadoop.entity;

import lombok.Data;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.io.Writable;
import org.apache.hadoop.mapreduce.lib.db.DBWritable;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * @author qiss
 * @create 2018-03-28 11:48
 **/
@Data
public class TestBean implements DBWritable,Writable{
    private Long id;
    private Integer action_type;
    private Double value;
    private String memo;

    public void write(PreparedStatement stmt) throws SQLException {
        stmt.setLong(1,id);
        stmt.setInt(2,action_type);
        stmt.setDouble(3,value);
        stmt.setString(4,memo);
    }

    public void readFields(ResultSet resultSet) throws SQLException {
        this.id = resultSet.getLong(1);
        this.action_type = resultSet.getInt(2);
        this.value = resultSet.getDouble(3);
        this.memo = resultSet.getString(4);
    }

    public void write(DataOutput out) throws IOException {
        out.writeLong(id);
        out.writeInt(action_type);
        out.writeDouble(value);
        Text.writeString(out,this.memo);
    }

    public void readFields(DataInput dataInput) throws IOException {
        this.id = dataInput.readLong();
        this.action_type = dataInput.readInt();
        this.value = dataInput.readDouble();
        this.memo = Text.readString(dataInput);
    }
}
